package my.mark.mybaibaoxiang.eventDemo.nhr;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

import java.util.Objects;

/**
 * @author wxming.
 * @date 2025/8/7.
 * @Description
 */

@Slf4j
@Component
public class PmMessageListener {

    @Async("pmThreadPoolTaskExecutor")
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void eventHandler(PmMessageEvent pmMessageEvent) {
        try {
            if (Objects.nonNull(pmMessageEvent)) {
                pmMessageEvent.getEventHandler().run();
            }
        } catch (Exception e) {
            log.error("PmMessageListener>>>eventHandler>>>" + pmMessageEvent.getEventName(), e);
        }
    }
}
